package window;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Iterator;
import java.util.List;

import javax.swing.JPanel;

import gameobj.ElementType;
import gameobj.GameObject;
import manager.ElementManager;



/**
 * @说明 游戏主面板
 * @author 007
 * @二作 Passerby
 * @修改
 * Passerby:将刷新时间(sleep)设置为了20，加快了刷新率
 */
public class MainPanel extends JPanel implements Runnable{
	private ElementManager em = null;
	
	public MainPanel() {
		init();
	}
	
	private void init() {
		em = ElementManager.get();
	}

	@Override
	public void paint(Graphics g) {
		super.paint(g);
		for (ElementType type : ElementType.values()) {
			List<GameObject> list = em.getList(type);
			for (GameObject obj : list) {
				if (obj.isActive()) {
					obj.render(g);
				}				
			}
		}
	}
	
	@Override
	public void run() {
		while(true) {
			this.repaint();
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}		
	}

}
